import * as types from '../types'
import  api from '../../fetch/api'

const state = {
	userinfo: [], //用户登录信息
	userstatus:false,//用户登录状态
	baseInfodata:[],//用户个人信息存放
	setcard:[],//
	CheckInList:[],//入住人列表
	CheckInfo:[],//入住人详情
	qiniuToken:'111',//七牛token
	GetBrowsedata:[],//浏览记录
	isCollect:false,
	EvalUateListdata:[],
	CouponListInfo:[],//优惠券
	Getidentitydata:[],//房东认证信息
	TpRnatype:0,//=1个人房东 =2企业房东
	landtypename:"请选择身份"
	
}
const actions = {
	setUserInfo({commit}, data) {
		commit(types.USER_LOGIN_INOF, data)
	},
	setUsersta({commit}, sta) {
		commit(types.USER_LOGIN_STATUS, sta)
	},
	setBaseInfo({commit}) {
		let getHiss=JSON.parse(sessionStorage.getItem("userinfo"))
		if (getHiss==null) {
			window.location="/login"
		}
		var ajaxSign = {
			"userId": getHiss.id.toString(),
			"token": getHiss.token,
			"source": "web",
		};
		let ajaxData = api.getAES(ajaxSign);
		api.GetBaseInfo(ajaxData)
		.then(res => {
			if(res.sta == 203) {
			commit(types.USER_BASE_INFO,false)
			window.location="/login"
			}
			if (res.sta==200) {
				
			commit(types.USER_BASE_INFO, res.result)
			sessionStorage.setItem("baseInfodata",JSON.stringify(res.result));
			}
		})
					
		
	},
	getCheckInList({commit}, data) {
		commit(types.USER_CHECKIN_LIST, data)
	},
	getCheckInInfo({commit}, data) {
		commit(types.USER_CHECKIN_INFO, data)
	},
	getUploadToken({dispatch,commit}) {
		let sess=JSON.parse(sessionStorage.getItem("userinfo"));
		let ajaxSign={
   		 source:"web",
   		 version:"3.2.7",
   		 token:sess.token,
   		 userId:sess.id.toString(),
		}
		let ajaxData = api.getAES(ajaxSign);
		api.uploadToken(ajaxData)
		.then(res=>{
			commit(types.USER_UPLOAD_TOKEN, res.result.token)
		})
	},
	getBrowseData({commit}, data) {
		commit(types.USER_BROWSE_DATA, data)
	},
	getIsCollect({commit}, data) {
		commit(types.USER_IS_COLLECT, data)
	},
	getEvalUateList({commit}, data) {
		commit(types.USER_EVALUATE_LIST, data)
	},
	getCouponListInfo({commit}, data) {
		commit(types.USER_COUPONLISTINFO, data)
	},
	getGetidentitydata({commit}, data) {
		commit(types.USER_GETIDENTITY_DATA, data)
	},
	setTpRnaType({commit}, data) {
		commit(types.USER_TPRNA, data)
	},
	setLandtypeName({commit}, data) {
		commit(types.USER_LANDTYPE_NAME, data)
	},
}
const getters = {
	userinfo: state => state.userinfo, //用户登录信息
	userstatus: state => state.userstatus, //用户登录状态
	baseInfodata: state => state.baseInfodata, //用户个人信息存放
	CheckInList: state => state.CheckInList, //用户个人信息存放
	CheckInfo: state => state.CheckInfo, //用户个人信息存放
	qiniuToken: state => state.qiniuToken, //七牛token
	GetBrowsedata: state => state.GetBrowsedata, //七牛token
	isCollect: state => state.isCollect, //是否收藏
	EvalUateListdata: state => state.EvalUateListdata, //我的评论
	CouponListInfo: state => state.CouponListInfo, //优惠券
	Getidentitydata: state => state.Getidentitydata, //=1个人房东 =2企业房东
	TpRnatype: state => state.TpRnatype, //=1个人房东 =2企业房东
	landtypename: state => state.landtypename, //=1个人房东 =2企业房东
}
const mutations = {
	[types.USER_LOGIN_INOF](state, res) {
		state.userinfo = res
	},
	[types.USER_LOGIN_STATUS](state, sta) {
		state.userstatus = sta
	},
	[types.USER_BASE_INFO](state, res) {
		state.baseInfodata = res
	},
	[types.USER_CARD](state, res) {
		state.setcard = res
	},
	[types.USER_CHECKIN_LIST](state, res) {
		state.CheckInList = res
	},
	[types.USER_CHECKIN_INFO](state, res) {
		state.CheckInfo = res
	},
	[types.USER_UPLOAD_TOKEN](state, res) {
		state.qiniuToken = res
	},
	[types.USER_BROWSE_DATA](state, res) {
		state.GetBrowsedata=res
	},
	[types.USER_IS_COLLECT](state, res) {
		state.isCollect=res
	},
	[types.USER_EVALUATE_LIST](state, res) {
		state.EvalUateListdata=res
	},
	[types.USER_COUPONLISTINFO](state, res) {
		state.CouponListInfo=res
	},
	[types.USER_GETIDENTITY_DATA](state, res) {
		state.Getidentitydata=res
	},
	[types.USER_TPRNA](state, res) {
		state.TpRnatype=res
	},
	[types.USER_LANDTYPE_NAME](state, res) {
		state.landtypename=res
	},
}
export default {
	state,
	actions,
	getters,
	mutations
}